package com.situ.day12;

import java.io.FileInputStream;
import java.io.FileNotFoundException;

import org.junit.Test;

public class Demo {
	public static void main(String[] args) {
		int num1 = 3;
		int num2 = 1;
		System.out.println("----start----");
		try {
			//需要检测的代码(可能会抛出异常，也可能不会抛出异常)
			int result = num1 / num2;
			int[] array = new int[2];
			array[2] = 3;
			//Unreachable
		}  catch (ArithmeticException e) {
			System.out.println("catch ArithmeticException");
			// 捕获异常后处理异常,程序不会崩溃
			e.printStackTrace();
		} catch (ArrayIndexOutOfBoundsException e) {
			System.out.println("catch ArrayIndexOutOfBoundsException");
			e.printStackTrace();
		} catch (Exception e) {
			System.out.println("catch Exception");
			e.printStackTrace();
		} finally {
			//一定会被执行的代码(不管异常抛不抛出都会执行，例如数据库释放连接)
			System.out.println("---finally----");
		}
		System.out.println("----end----");
	}
	
	
	public static void main11(String[] args) {
		int num1 = 3;
		int num2 = 1;
		System.out.println("----start----");
		try {
			//需要检测的代码(可能会抛出异常，也可能不会抛出异常)
			int result = num1 / num2;
		} catch (ArithmeticException e) {
			System.out.println("catch ArithmeticException");
			// 捕获异常后处理异常,程序不会崩溃
			e.printStackTrace();
		} finally {
			//一定会被执行的代码(不管异常抛不抛出都会执行，例如数据库释放连接)
			System.out.println("---finally----");
		}
		System.out.println("----end----");
	}
	
	public static void main111(String[] args) {
		Person person = new Person();
		person.setId(1);
		person.setName("zhangsan");
		System.out.println(person);
		System.out.println(person.toString());
	}
	
	
	@Test
	public void test1() {
		Person person = new Person();
		person.setId(12);
		System.out.println(person.getId());
		person = getPerson();
		person.setId(22);
	}
	
	@Test
	public void test2() {
		int i = 2 / 0;
		System.out.println("Demo.test2()");
	}
	
	@Test
	public void test3() {
		Student student = new Student();
		Person person = new Person();
		Person p = student;
		Student stu = (Student)person;
	}


	private Person getPerson() {
		return null;
	}
	
	@Test
	public void test44() {
		// Unhandled exception type FileNotFoundException
		try {
			FileInputStream fileInputStream = new FileInputStream("a.txt");
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	@Test
	public void test441() {
		
	}
	
	
	
	
	
	
	
}
